const { getData_default, resultData_default } = require("../tool/tool")
const fs = require('fs')

let obj = {}
function storage(str, obj_) {
  if (obj_) {
    obj[str] = obj_;
    return str;
  } else {
    return obj[str]
  }
}

const get_method = {
  token(req, resp) {
    // console.log('', req.url);
    // console.log('', req.query);
    // console.log('', req.body);
    resp.send('date')
  },
  test(req, resp) {
    resp.json({
      "status": "OK",
      "msg": "",
      "data": {
        "content": {
          "title": "port-code-enquiry",
          "type": "table",
        }
      }
    })
  },
  favorite(req, resp) {
    resp.status(202)
    resp.json({
      "status": "OK",
      "msg": "",
      "data": {
        "content": {
          "favorite": [
            "/covcod-report",
            "/movement-report",
          ]
        }
      }
    })
  },
  result(req, resp) {
    if (req.query.jobId === 'storage_report') resp.json(resultData_default({
      title: "storage-report",
      colConfig: ['portName', 'countryName', 'unPortCode', 'linePortCode', 'age', 'name']
    }, storage(req.query.jobId)));
    else if (req.query.jobId === 'emptyContainerList') resp.json(resultData_default({
      title: "empty-container-list",
      colConfig: ['Voyage', 'Vessel', 'Container Number', 'Category', 'Carrier Type', 'Size']
    }, storage(req.query.jobId)));
    else if (req.query.jobId === 'emptyPoolDailyReport') resp.json(resultData_default({
      title: "empty-container-list",
      colConfig: ['operatorGroup', 'id']
    }, storage(req.query.jobId)));
    else if (req.query.jobId === 'emptyPoolMonthlyReport') resp.json(resultData_default({
      title: "empty-container-list",
      colConfig: ['operatorGroup', 'id', 'ReportDate']
    }, storage(req.query.jobId)));
    else resp.json({});
  },
  storage_report(req, resp) {
    resp.json({
      jobId: storage('storage_report', req.query)
    })
  },
  port_code_enquiry(req, resp) {
    resp.json(getData_default({
      title: "port-code-enquiry",
      colConfig: ['portName', 'countryName', 'unPortCode', 'linePortCode', 'age', 'name']
    }, req.query))
  },
  getVesselNameList(req, resp) {
    resp.json({
      "status": "OK",
      "msg": "",
      "data": {
        "content": {
          "title": "Vessel Name",
          "type": "param",
          "data": ["OOCL AMERICA", "OOCL AMERICA1", "OOCL AMERICA2", "OOCL AMERICA3",]
        }
      }
    }
    )
  },
  getVesselVoyageList(req, resp) {
    resp.json({
      "status": "OK",
      "msg": "",
      "data": {
        "content": {
          "title": "Voyage Number",
          "type": "param",
          "data": ["111W", "111W1", "111W2", "111W3",]
        }
      }
    }
    )
  },
  getOperators(req, resp) {
    resp.json({
      "status": "OK",
      "msg": "",
      "data": {
        "content": {
          "title": "Voyage Number",
          "type": "param",
          "data": ["AEM", "ALI", "ALM", "ANH", "ANL", "APL",]
        }
      }
    }
    )
  },
  getEmail(req, resp) {
    resp.json({
      "data": {
        "email": "sjdiow***lsdj@qq.com"
      }
    })
  },
  emptyContainerList(req, resp) {
    resp.json({
      jobId: storage('emptyContainerList', req.query)
    })
  },
  emptyContainerListDetail(req, resp) {
    resp.json({
      jobId: storage('emptyContainerList', req.query)
    })
  },
  ucInventoryList(req, resp) {
    resp.json({
      jobId: storage('emptyContainerList', req.query)
    })
  },
  containerInventoryListAndSummary(req, resp) {
    resp.json({
      jobId: storage('emptyContainerList', req.query)
    })
  },
  emptyPoolDailyReport(req, resp) {
    resp.json({
      jobId: storage('emptyPoolDailyReport', req.query)
    })
  },
  emptyPoolMonthlyReport(req, resp) {
    resp.json({
      jobId: storage('emptyPoolMonthlyReport', req.query)
    })
  },
  emptyPoolReportById(req, resp) {
    let { id } = req.query
    resp.status(200)
    // fs.readFile('C:/Users/weijun.wu/Desktop/test_API/src/images/3.jpeg', (err, file) => {
    fs.readFile('C:/Users/weijun.wu/Desktop/test_API/src/css/index.css', async (err, file) => {
      // const response = await fetch(`data:text;base64,${file.toString('base64')}`);
      // const blob = await response.blob(); // 获取 Blob 类型
      resp.send({
        // file: blob,
        file: `data:css;base64,${file.toString('base64')}`,
        fileName: id + '.css'
      })
    })
  },
}

module.exports = get_method;